# coding=utf-8
import json
import requests


class BaseRequest:
    def send_post(self,url,data):
        '''
        发送post请求
        :param url:
        :param data:
        :return:
        '''
        res = requests.post(url=url, data=data)
        return res

    def send_get(self,url,data):
        '''
        发送get请求
        :param url:
        :param data:
        :return:
        '''
        res = requests.get(url=url, params=data)
        return res

    def run_main(self, url, data, method):
        '''
        执行方法
        :param url:
        :param data:
        :param method:
        :return:
        '''
        if method == 'post':
            res = self.send_post(url,data).text
        else:
            res = self.send_get(url,data).text
        try:
            res = json.loads(res)
        except:
            print('解析错误')
        return res

request = BaseRequest()